package com.yjy.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.system.comm.util.SpringContextUtil;
import com.system.common.pojo.SysRole;
import com.yjy.service.SysUserService;
import com.yjy.service.SysUserServiceImpl;

public class UserIdTag extends BodyTagSupport {
	
	private static final long serialVersionUID = 1L;
	private String userId;
	
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	@Override
	public int doStartTag() throws JspException { // 在标签开始处出发该方法
		JspWriter writer = this.pageContext.getOut();
		SysUserService sysUserService=(SysUserServiceImpl)SpringContextUtil.getBean("sysUserServiceImpl");
		try {
			SysRole role=sysUserService.getByUserId(userId);
			if(role!=null){
				writer.write(role.getRoleName());
			}else{
				writer.write("");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return BodyTagSupport.SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException {
		return BodyTagSupport.EVAL_BODY_INCLUDE;
	}
	
}
